def can_partition(arr, m):
    total_sum = sum(arr)
    if total_sum % m != 0:
        return False  # 如果不能整除，返回False
    
    target = total_sum // m
    n = len(arr)
    partitions = [0] * m
    
    # 回溯法尝试分配每个数
    def dfs(index):
        if index == n:
            return all(partition == target for partition in partitions)
        
        for i in range(m):
            if partitions[i] + arr[index] <= target:
                partitions[i] += arr[index]
                if dfs(index + 1):
                    return True
                partitions[i] -= arr[index]
            
            # 优化：避免重复的状态
            if partitions[i] == 0:
                break
        
        return False
    
    return dfs(0)

def max_m_partitions(arr):
    m = 1
    while can_partition(arr, m):
        m += 1
    return m - 1

# 测试用例
if __name__ == "__main__":    
    # 测试用例
    test_cases = [
        [6, 4, 3, 3, 2],
        [10, 8, 6, 4, 2],
        [7, 7, 7],
        [5, 4, 3, 2, 1],
        [5, 4, 3, 2],
    ]
    
    for i, test in enumerate(test_cases):
        print(f"测试用例 {i+1} {test}: 最大的m值为 {max_m_partitions(test)}")
